<?php
namespace app\index\controller;

use think\Controller;

class Index extends Common
{
    public function _initialize()
    {
        //dump($_SERVER);
        parent::_initialize();
        $this->assign('active', '首页');
    }
    
    // 首页
    public function index() {
        // 获取 banner
        $banner = db('banner')->where('is_show', 1)->select();
        $this->assign('banner', $banner);

        // 获取首页推荐产品
        $product = db('product')->alias('p')
            ->field('p.name, p.id, p.is_index, pi.image')
            ->join('osl_product_image pi', 'p.id = pi.product_id and pi.is_main = 1', 'LEFT')
            ->where('p.is_index', 1)
            ->order('p.id desc')
            ->limit(8)
            ->select();
        $this->assign('product', $product);

        // 获取公司介绍
        $gsjs = db('article')->alias('a')->field('a.*, ac.info')->join("osl_article_content ac", "ac.article_id = a.id", "LEFT")->where('a.id', 10)->find();
        $this->assign('gsjs', $gsjs);

        // 获取合作案例
        $casus = db('casus')->order("id desc")->limit(8)->select();
        $this->assign('casus', $casus);

        // 获取特色服务
        $futs = db('page')->where('make', 'futs')->find();
        $this->assign('futs', $futs);

        // 获取公司新闻
        $gsxw = db('news')->where('cate_id', '8')->order("id desc")->limit(7)->select();
        $this->assign('gsxw', $gsxw);

        // 获取行业动态
        $hydt = db('news')->alias('n')->field('n.*, nc.info')->join("osl_news_content nc", "nc.news_id = n.id", "LEFT")->where('n.cate_id', '9')->order("n.id desc")->limit(3)->select();
        foreach ($hydt as $k => $v) {
            $hydt[$k]['time_date'] = date('Y-m', $v['add_time']);
            $hydt[$k]['time_day'] = date('d', $v['add_time']);
        }
        $this->assign('hydt', $hydt);

        return view();
    }
}
